$(function(){
	path = "http://v.gaodun.com";
	if(typeof(GAODUNER) != "undefined")
		path = GAODUNER.path;
	
	var url = path+'/Course/getCourseHot?callback=?';
	getnoticecount();
	var message = 0;
	var msgsarr = new Array([0],[0],[0],[0]);
	$(".mark").click(function(){
		index=$("#message em.current").index();
		url = path+'/Message/marknotice?callback=?';
		$.getJSON(url,{type:index,rtype:2},function(data){
			//var data=eval("("+data+")");
			if(data.status == 1){
				html="没有新通知！";
				$("div.tab_box > div.contDiv").eq(index).html(html);
				var count = '';
				$("#remindCls").hide();
				$("#remindCls").html(count);
			}
		});
	});
	
	$("#message").hover(function(){
		msg = this;
		if(message == '0'){
			url = path+'/Message/allmsg?callback=?';
			$.getJSON(url,{rtype:2},function(data){
				//var data=eval("("+data+")");
				if(data.status == 1){
					html = '';
					if(data.data){
						html+='<ul>';
						for(i=0;i<data.data.length;i++){
							if(data.data[i].type == ''){
								html+='	<li class="lst">';
								html+='		<div class="clearfix">';

								if(data.data[i].assitant_id==5){
									html+='			<em class="lft"><span class="cGreen">直播任务通知</span></em>';
								}else if(data.data[i].assitant_id==6){
									html+='			<em class="lft"><span class="cGreen">预约通知</span></em>';
								}else if(data.data[i].assitant_id==8){
									html+='			<em class="lft"><span class="cGreen">学员反馈通知</span></em>';
								}else if(data.data[i].assitant_id==12){
									html+='			<em class="lft"><span class="cGreen">史上最有趣会计课程火爆上线</span></em>';
								}
								else{
									html+='			<em class="lft"><span class="cGreen">高顿名师</span> 回答了你的问题</em>';
								}
								html+='			<em class="cGray date">'+getLocalTime(data.data[i].regdate)+'</em>';
								html+='		</div>';
								html+='		<div class="hd cGreen" onclick="return viewed(this);" data-id="'+data.data[i].qaid+'" data-type="4">'+data.data[i].pcontent+'</div>';
								html+='		<div class="notDet hideTr">';
								html+='			<div class="cont">'+data.data[i].content+'</div>';
								//html+='			<div><input class="ipt" type="text" placeholder="回复：" /> <input type="button" class="btn btn-small btn-success" value="提交" /></div>';
								html+='		</div>';
								html+='	</li>';
							}else if(data.data[i].type == '2'){
								html+='	<li class="lst" onclick="return viewed(this);" data-id="'+data.data[i].nid+'" data-type="'+data.data[i].type+'">';
								html+='		<div class="clearfix">';
								html+='			<em class="lft"><span class="cGreen">'+data.data[i].title+'</span> 上传了新课程</em>';
								html+='			<em class="cGray date">'+getLocalTime(data.data[i].regdate)+'</em>';
								html+='		</div>';
								html+='		<div class="cGreen">'+data.data[i].summary+'</div>';
								html+='	</li>';
							}else{
								html+='	<li class="lst">';
								html+='		<div class="hd clearfix" onclick="return viewed(this);" data-id="'+data.data[i].nid+'" data-type="'+data.data[i].type+'"><span class="cGreen">'+data.data[i].title+'</span><em class="cGray date">'+getLocalTime(data.data[i].regdate)+'</em></div>';
								html+='		<div class="notDet hideTr">';
								html+='		<div class="cont">'+data.data[i].summary+'</div>';
								html+='	</div>';
								html+='	</li>';
							}
						}
					}else{
						html+='没有新通知！';
					}
					$(msg).find("div.contDiv:first").html(html);
					$(msg).find("div.contDiv:first").show();
					message ++ ;
				}
			});
		}
	},function(){});
	
	$("#message .tab_menu em").click(function(){
		var index =  $(this).index();
		if(index == 1 && msgsarr[1]==0){
			url = path+'/Message/qandamsg?callback=?';
			$.getJSON(url,{rtype:2},function(data){
				//var data=eval("("+data+")");
				if(data.status == 1){
					html = '';
					if(data.data){
						html+='<ul>';
						for(i=0;i<data.data.length;i++){
							html+='	<li class="lst">';
							html+='		<div class="clearfix">';


							if(data.data[i].assitant_id==5){
									html+='			<em class="lft"><span class="cGreen">直播任务通知</span></em>';
								}else if(data.data[i].assitant_id==6){
									html+='			<em class="lft"><span class="cGreen">预约通知</span></em>';
								}else if(data.data[i].assitant_id==8){
									html+='			<em class="lft"><span class="cGreen">学员反馈通知</span></em>';
								}
								else{
									html+='			<em class="lft"><span class="cGreen">高顿名师</span> 回答了你的问题</em>';
								}


							html+='			<em class="cGray date">'+getLocalTime(data.data[i].regdate)+'</em>';
							html+='		</div>';
							html+='		<div class="hd cGreen" onclick="return viewed(this);" data-id="'+data.data[i].id+'" data-type="4">'+data.data[i].pcontent+'</div>';
							html+='		<div class="notDet hideTr">';
							html+='			<div class="cont">'+data.data[i].content+'</div>';
							//html+='			<div><input class="ipt" type="text" placeholder="回复：" /> <input type="button" class="btn btn-small btn-success" value="提交" /></div>';
							html+='		</div>';
							html+='	</li>';
						}
					}else{
						html+='没有新通知！';
					}
					//alert(html);
					$("div.tab_box > div").eq(index).html(html);
					$("div.tab_box > div").eq(index).show();
					msgsarr[1]++ ;
				}
			});
		}else if(index==2 && msgsarr[2]==0){
			url = path+'/Message/noticemsg?callback=?';
			$.getJSON(url,{id:1,rtype:2},function(data){
				//var data=eval("("+data+")");
				if(data.status == 1){
					html = '';
					if(data.data){
						html+='<ul>';
						for(i=0;i<data.data.length;i++){
							html+='	<li class="lst" onclick="return viewed(this);" data-id="'+data.data[i].id+'" data-type="'+data.data[i].type+'">';
							html+='		<div class="clearfix">';
							html+='			<em class="lft"><span class="cGreen">'+data.data[i].title+'</span> 上传了新课程</em>';
							html+='			<em class="cGray date">'+getLocalTime(data.data[i].regdate)+'</em>';
							html+='		</div>';
							html+='		<div class="cGreen">'+data.data[i].summary+'</div>';
							html+='	</li>';
						}
					}else{
						html+='没有新通知！';
					}
					$("div.tab_box > div").eq(index).html(html);
					$("div.tab_box > div").eq(index).show();
					msgsarr[2]++ ;
				}
			});
		}else if(index==3 && msgsarr[3]==0){
			url = path+'/Message/noticemsg?callback=?';
			$.getJSON(url,{id:2,rtype:2},function(data){
				//var data=eval("("+data+")");
				if(data.status == 1){
					html = '';
					if(data.data){
						html+='<ul>';
						for(i=0;i<data.data.length;i++){
							html+='	<li class="lst">';
							html+='		<div class="hd clearfix" onclick="return viewed(this);" data-id="'+data.data[i].id+'" data-type="'+data.data[i].type+'"><span class="cGreen">'+data.data[i].title+'</span><em class="cGray date">'+getLocalTime(data.data[i].regdate)+'</em></div>';
							html+='		<div class="notDet hideTr">';
							html+='		<div class="cont">'+data.data[i].summary+'</div>';
							html+='	</div>';
							html+='	</li>';
						}
					}else{
						html+='没有新通知！';
					}
					$("div.tab_box > div").eq(index).html(html);
					$("div.tab_box > div").eq(index).show();
					msgsarr[3]++ ;
				}
			});
		}
	
	});
	function getLocalTime(nS){   
		return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');   
	}
})
function viewed(e){
	id = $(e).attr("data-id");
	type = $(e).attr("data-type");
	$.getJSON(path+"/Message/markviewed?callback=?",{id:id,type:type,rtype:2},function(data){
		//var data=eval("("+data+")");
		if(data.status == 1){
			var count = $("#remindCls").html() - 1;
			if(count == '0'){
				count = '';
				$("#remindCls").hide();
			}
			$("#remindCls").html(count);
		}
	});
}

function getnoticecount(){
	$.getJSON(path+"/Message/_getallcount?callback=?",{rtype:2},function(data){
		//var data=eval("("+data+")");
		if(data.status == 1){
			if(data.data != '0'){
				$("#remindCls").show();
				$("#remindCls").html(data.data);
			}else{
				$("#remindCls").hide();
			}
		}
	});
}